﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace CDMS
{
    public partial class frmLogin : DevExpress.XtraEditors.XtraForm
    {
        public frmLogin()
        {
            InitializeComponent();
            txtUser.Enter += txtUser_Enter;
            txtPassword.Enter += txtPassword_Enter;

        }

        void txtPassword_Enter(object sender, EventArgs e)
        {
            TextEditFocusAtEnd(sender as TextEdit);
        }

        void txtUser_Enter(object sender, EventArgs e)
        {
            TextEditFocusAtEnd(sender as TextEdit);
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUser.Text))
            {
                FormGlobals.Message_Warning("Tài khoản đăng nhập không được để trống!","Cảnh báo");
                return;
            }
            if (txtUser.Text.Equals("TRONGVM") && txtPassword.Text.Equals("123456"))
            {
                Program.userName = txtUser.Text;
                Program.passWord = txtPassword.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                FormGlobals.Message_Error("Tài khoản đăng nhập không tồn tại!", "Lỗi");
                this.DialogResult = DialogResult.Cancel;
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            
        }

        void TextEditFocusAtEnd(TextEdit textEdit)
        {
            textEdit.BeginInvoke(new MethodInvoker(delegate
            {
                textEdit.SelectionLength = textEdit.Text.Length;
                textEdit.SelectionStart = 0;
            }));
        }
    }
}